import {
  getRecordsByUserIdAPI
} from '../../../api/record'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userId: 0,
    recordList: [],
    record: {
      value: 'all',
      options: [{
        value: 'all',
        label: '最近收藏',
      }, ],
    },
    sorter: {
      value: 'default',
      options: [{
          value: 'default',
          label: '默认排序',
        },
        {
          value: 'price',
          label: '价格从高到低',
        },
      ],
    },
  },
  async getRecordsByUserId(userId) {
    let that = this
    getRecordsByUserIdAPI(userId).then(res => {
      if (res.code == 200) {
        that.setData({
          recordList: res.result
        })
      }
    })
  },
  onChange(e) {
    this.setData({
      'record.value': e.detail.value,
    });
  },
  onLoad(options) {
    let user = wx.getStorageSync('user')
    if (user) {
      this.setData({
        userId: user.id,
      })
    }
    this.getRecordsByUserId(this.data.userId)
  },
  onShow() {
    this.onLoad()
  },
})